export default class CustomPalette {
    constructor(create, bpmnFactory, elementFactory, palette) {
        this.create = create;
        this.bpmnFactory = bpmnFactory;
        this.elementFactory = elementFactory;
        palette.registerProvider(this);
    }


    // 这个是绘制palette的核心，函数名不要变
    getPaletteEntries() {
        const bpmnFactory = this.bpmnFactory;
        const elementFactory = this.elementFactory;
        const create = this.create;

        function createTask() {
            return function (event) {
                const businessObject = bpmnFactory.create('bpmn:Task');
                const shape = elementFactory.createShape({
                    type: 'bpmn:Task',
                    businessObject
                });
                console.log(shape) // 只在拖动或者点击时触发
                create.start(event, shape);
            }
        }

        return {
            'create.my-task-one': {
                title: '我是自定义节点-草莓蛋糕',    // 鼠标悬浮到节点上显示的文字
                className: 'icon-custom bpmn-icon-my-task-one',   // 样式名
                action: {      // 操作该节点时会触发的事件，此时只注册一个拖动事件即可，否则拖动时没有效果
                    dragstart: createTask(),
                    click: createTask() // 点击时调用的事件
                }
            }
        };
    }
}
CustomPalette.$inject = [
    'create',
    'bpmnFactory',
    'elementFactory',
    'palette'
];